<?php
	require_once PATH_OBJECT.'dataObject.php';
	
class dataObject_elementdico extends dataObject
{
 /* @desc    Identifiant de l'element du dictionnaire
     * @var     int
     */
    public $_IDENTIFIANT_ELEMENT = 0;
    
    /**
     * @desc    Code rattaché à l'element
     * @var     varchar
     */
    public $_CODE_ELEMENT = '';

    /**
     * @desc    Nom de l'element
     * @var     int
     */
    public $_NOM_ELEMENT = '';

    /**
     * @desc   identifiant dans la table DICTIONNAIRE qui est associé à l'element
     * @var     int
     */
    public $_IDENTIFIANT_TABLE = 0;
    
    const ELT_STAT_ENCAISSEMENT = 'E';
    const ELT_STAT_PRODUCTION = 'P';
    const ELT_STAT_SINISTRALITE = 'S';
    
    const TYP_ASSURE_ENFANT = 'E';
    
    const MOTIF_AUCUN_ASSURE_CONTRAT = 'PA';
    
	public function __construct( $iId=0 )
    {
       parent::__construct();

       if ( $iId != 0 )
       {
            $sQuery = "SELECT   *   /*+ dataObject_elementdico::__construct */  
                       FROM elementdico 
            		   WHERE Identifiant_element = ".$iId;
            
            $aRows =  self::$_oConnexion->query($sQuery);
			$aRow = $aRows[0];

            $this->_MENU_ID            = $iId;
            $this->_MENU_NOM           = $aRow["Code_element"]; 
            $this->_MENU_PARENT_ID     = $aRow["Nom_element"];
            $this->_MENU_NIVEAU        = $aRow["Identifiant_table"];
          
       }
    }
    /**
     * récupere la table menu selon le(s) criter(s) précisés ou pas 
	 */
    public static function elementdico_getNomFromCode( $sCodeElement, $sCodeTable )
    {
        $sNom = "";
    	$sQuery = "SELECT Nom_element 
    				FROM dictionnaire,elementdico 
    				WHERE dictionnaire.Code_table = '".$sCodeTable."'
					 AND dictionnaire.Identifiant_table = elementdico.Identifiant_table
					 AND Code_element = '".$sCodeElement."'";
    	
        $aRow =  self::$_oConnexion->query($sQuery);
		//$sNom = htmlentities($aRow[0]['Nom_element']);
		$sNom = $aRow[0]['Nom_element'];
		
        return $sNom;
    }
    
    
	/** renvoi les noms des éléments dictionnaire selon le code table donné. 
	 */
    function elementdico_getListFromCode($sCodeTable)
    {

    	$sQuery = "SELECT Nom_element, Code_element, Identifiant_element
    				FROM dictionnaire,elementdico 
    				WHERE dictionnaire.Code_table = '".$sCodeTable."'
					AND dictionnaire.Identifiant_table = elementdico.Identifiant_table";
    	
        $aRow =  self::$_oConnexion->query($sQuery);
		/*if(!empty($aRow))
		{
			foreach($aRow as $i=>$Row)
			{
				$aRow[$i]['Nom_element'] = htmlentities($Row['Nom_element']);
			}
		}*/
        return $aRow;
    }
   
	public static function  elementdico_getArrayStatistique($sCode)
    {
    	$aEntete = array( 0 => "ANNEE",
						  1 => "MOIS"
						 );
    
	     switch($sCode)
	     {
	     	case self::ELT_STAT_ENCAISSEMENT:
	     		$aEntete[] = "CODE REGION";
				$aEntete[] = "LIBELLE REGION";
				$aEntete[] = "CODE UNITE";
				$aEntete[] = "LIBELLE UNITE";
				$aEntete[] = "CODE AGENT";
				$aEntete[] = "NOM AGENT";
				$aEntete[] = "NUMERO CONTRAT";
				$aEntete[] = "OFFRE";
				$aEntete[] = "PRODUIT";
				$aEntete[] = "FORMULE";
	     		$aEntete[] = "FREQUENCE REGLEMENT";
				$aEntete[] = "DATE DEBUT ECHEANCE";
				$aEntete[] = "DATE FIN ECHEANCE";
				$aEntete[] = "ETAT ECHEANCE";
				$aEntete[] = "MONTANT ECHEANCE";
				$aEntete[] = "DATE REGLEMENT ECHEANCE";
				$aEntete[] = " ";
				     		
				break;
	     	case self::ELT_STAT_PRODUCTION:
	     		$aEntete[] = "SEMAINE";
	     		$aEntete[] = "CODE REGION";
				$aEntete[] = "LIBELLE REGION";
				$aEntete[] = "CODE UNITE";
				$aEntete[] = "LIBELLE UNITE";
				$aEntete[] = "CODE AGENT";
				$aEntete[] = "NOM AGENT";
				$aEntete[] = "NUMERO CONTRAT";
				$aEntete[] = "DATE EFFET CONTRAT";
				$aEntete[] = "OFFRE";
				$aEntete[] = "PRODUIT";
				$aEntete[] = "FORMULE";
				$aEntete[] = "MONTANT COTISATION";
				$aEntete[] = "MONTANT DROIT ENTREE";
				$aEntete[] = "FREQUENCE REGLEMENT";
				$aEntete[] = "SOUS TYPE EVENEMENT";
				$aEntete[] = " ";
				
				break;
	     	case self::ELT_STAT_SINISTRALITE:
	     		$aEntete[] = "SEMAINE";
	     		$aEntete[] = "CODE REGION";
				$aEntete[] = "LIBELLE REGION";
				$aEntete[] = "CODE UNITE";
				$aEntete[] = "LIBELLE UNITE";
				$aEntete[] = "CODE AGENT";
				$aEntete[] = "NOM AGENT";
				$aEntete[] = "NUMERO CONTRAT";
				$aEntete[] = "OFFRE";
				$aEntete[] = "PRODUIT";
				$aEntete[] = "FORMULE";
	     		$aEntete[] = "TYPE SINISTRE";
				$aEntete[] = "DATE SURVENANCE SINISTRE";
				$aEntete[] = "DATE DECLARATION SINISTRE";
				$aEntete[] = "ETAT SINISTRE";
				$aEntete[] = "DECISION ASSUREUR";
				$aEntete[] = "MOTIF REFUS";
				$aEntete[] = "TYPE PRESTATION";
				$aEntete[] = "MONTANT PRESTATION";
				$aEntete[] = "DATE REGLEMENT PRESTATION";
				$aEntete[] = " ";
				
				break;
	     	default:
	     		break;
	     }
        return $aEntete;
    }
    
	public function elementdico_getStatistique($sCode,$sDateDebut,$sDateFin)
    {
    	$aData = array();
    	switch($sCode)
	     {
	     	case self::ELT_STAT_ENCAISSEMENT:
	     		$aData = dataObject_evenement::evenement_getStatNiveauEncaissement($sDateDebut,$sDateFin);
				
				     		
				break;
	     	case self::ELT_STAT_PRODUCTION:
	     		$aData = dataObject_evenement::evenement_getStatNiveauProduction($sDateDebut,$sDateFin);
				
				break;
	     	case self::ELT_STAT_SINISTRALITE:
	     		$aData = dataObject_evenement::evenement_getStatNiveauSinistre($sDateDebut,$sDateFin);
				break;
	     }
        return $aData;
    }
}
?>